package top.yamhk.agent.entity.dto;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.List;

/**
 * #DMX
 *
 * @author 应勋耀
 * @date 2022/12/1 11:10
 */
@Slf4j
public class Solutions {

    public static AllInOne doGetTableDoc(File file) {
        Object test;
        String keyword = "";
        String remark = "";
        String pathStr = "";
        String path = "";
        String method = "";
        String template = "keyword,remark";
        AllInOne one = new AllInOne();
        one.setJavaFileName(file.getName());
        //
        List<String> strings = FileUtil.readUtf8Lines(file);
        //
        String preStr = "";
        for (String string : strings) {
            if (preStr.contains("**") && string.indexOf("*") == 1) {
                one.setJavaFileRemark(string.substring(3));
            }
            if (string.contains("TableName")) {
                one.setTableName(string.substring(12, string.length() - 2));
            }
            preStr = string;
            //备注
            remark = string.contains("*") && !string.contains("@") && !string.contains("/") && string.trim().length() > 1 ? string : remark;
            if (string.contains("private") && !string.contains("final")) {
                //字段
                String[] split = string.split(" ");
                keyword = string.contains("private") && split.length >= 7 ? split[6].replace(";", "") : keyword;
                String tmp1 = template;
                //类型
                String typeTrim = split[5];
                //注释
                String remarkTrim = remark.replace("*", "").trim();

                tmp1 = tmp1.replace("remark", remarkTrim);
                tmp1 = tmp1.replace("keyword", keyword);
                //System.out.println(keyword + "," + remarkTrim);
                one.getKey().add(keyword);
                one.getVal().add(remarkTrim);
                one.getRem().add(remarkTrim);
                one.getTyp().add(typeTrim);
            }
        }
        return one;
    }
}
